//
//  TestPresenter.m
//  MVP3
//
//  Created by 李煜 on 2024/6/21.
//https://www.cnblogs.com/self-epoch/p/16289602.html

#import "TestPresenter.h"
#import "TestView.h"
#import "TestModel.h"
@interface TestPresenter()<TestViewDelegate> // 接受协议

@end

@implementation TestPresenter

// P 完全负责 V、M 的交互
-(void)setUP{
    NSLog(@"---- P、C 两者绑定成功 -----");
    [self makeSomethings];
}

-(void)makeSomethings{
    
    // 加载视图
    TestView *tView = [[TestView alloc] initWithFrame:CGRectMake(30, 80, self.controller.view.frame.size.width - 60, 200)];
    tView.backgroundColor = [UIColor redColor];
    [self.controller.view addSubview:tView];
    tView.delegate = self;
    
    // 加载数据模型
    TestModel *tModel = [TestModel new];
    tModel.name = @"QQ";
    
    // 赋值
    tView.TVLabel.text = tModel.name;
    // V 可向 M 提供一些简单入口进行交互
    [tView setName:tModel.name withimage:nil];
}

// 代理：随机色
- (void)doSomethings{
    self.controller.view.backgroundColor = [UIColor colorWithRed:arc4random()%255/255.0
                                                           green:arc4random()%255/255.0
                                                            blue:arc4random()%255/255.0
                                                           alpha:1.0];
}

@end
